﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EnvironmentalMonitor.Support.Business.Environmental;
using EnvironmentalMonitor.Support.Business;
using EnvironmentalMonitor.Support.Module;
using EnvironmentalMonitor.Support.Resource;

namespace EnvironmentalMonitor.WebApplication.Environmental.Detector
{
    public partial class View : EnvironmentalMonitor.WebApplication.Abstract.AbstractList
    {
        private string _Description;
        public override string Description
        {
            get
            {
                return this._Description;
            }
        }

        private string _ListJsonUrl;
        public override string ListJsonUrl
        {
            get
            {
                return this._ListJsonUrl;
            }
        }

        private string _SaveJsonUrl;
        public override string SaveJsonUrl
        {
            get
            {
                return this._SaveJsonUrl;
            }
        }

        public override string DeleteJsonUrl
        {
            get
            {
                return string.Format("{0}Environmental/Detector/DeleteJson.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath);
            }
        }

        public string RefreshJsonUrl
        {
            get
            {
                return string.Format("{0}Environmental/Detector/Refresh.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath);
            }
        }

        public string WarringSoundUrl
        {
            get
            {
                return string.Format("{0}Image/Default.wav", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath);
            }
        }

        private string _FloorPlan;
        public string FloorPlan
        {
            get
            {
                return this._FloorPlan;
            }
        }

        private int _DataCacheInterval;
        public int DataCacheInterval
        {
            get
            {
                return this._DataCacheInterval;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            const string MACHINE_ID = "machineId";

            string machineId = this.ParameterString(MACHINE_ID);

            MachineBusiness business = new MachineBusiness();
            EnvironmentalMonitor.Support.Module.Environmental.Machine module = business.QueryByGuid(machineId);

            if (module != null)
            {
                this._Description = string.Format("{0} 的{1} 的探头", module.RoomName, module.Name);
                this._ListJsonUrl = string.Format("{0}Environmental/Detector/ViewJson.aspx?machineId={1}", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath, module.Guid);
                this._SaveJsonUrl = string.Format("{0}Environmental/Detector/ViewDataCacheJson.aspx?machineId={1}", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath, module.Guid);
                this._FloorPlan = string.Format("{0}{1}", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath, module.FloorPlan);
                this._DataCacheInterval = module.Interval * 1000;
            }
        }
    }
}